<template>
  <!-- 
  <van-cell 
   class="article-item" 
   //通过js来进行传参
   @click="toArticleDetail"
    
   //通过router-link的to方式
   :to='{
     name:"ArticleDetail",
     params: {
       articleId: "" + article.art_id
     }
   }'

  //query的router-link的to方式
   :to='{
     path:"article",
     query: {
       articleId: "" + article.art_id
     }
   }'
  > -->
  <van-cell 
   class="article-item" 
   :to='{
     name:"ArticleDetail",
     params: {
       articleId: "" + article.art_id
     }
   }'
  >
    <!-- 文章的标题 -->
    <div class="title van-multi-ellipsis--l2" slot="title">{{ article.title }}</div>
    <div slot="label">
      <!-- 3张图的方式 -->
      <div class="cover-wrap" v-if="article.cover.images.length > 1">
        <div 
          class="cover-wrap-item"
          v-for="(img,index) in article.cover.images"
          :key="index"
        >
          <van-image
            class="cover-item"
            fit="cover"
            :src="img"
          />
        </div>
      </div>
      <div class="label-wrap">
        <span>置顶</span>
        <span>{{ article.aut_name }}</span>
        <span>{{ article.comm_count }}评论</span>
        <span>{{ article.pubdate | relativeTime }}</span>
      </div>
    </div>
    <!-- 默认插槽的名字叫default, 可以省略 -->
    <div slot="default" v-if="article.cover.images.length === 1">
      <van-image
        class="right-cover"
        fit="cover"
        :src="article.cover.images[0]"
      />
    </div>
  </van-cell>
</template>

<script>
export default {
  name: "ArticleItem",
  components: {},
  props: {
    article: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  methods: {
    // 路由传参 （1）params (2)query
    toArticleDetail() {
      // (1)params  
      // 路由表那边的路径 path:'/article/:articleId'
      // this.$router.push({
      //   name: "ArticleDetail",
      //   params: {
      //     articleId: this.article.art_id
      //   }
      // });

      // (2)query 
      // 路由表那边的路径 path:'/article'
      // this.$router.push({
      //   path: "article",
      //   query: {
      //     articleId: this.article.art_id
      //   }
      // })

    }
  },
  created() {},
  mounted() {},
};

/**
 * 关于第三方图片资源403问题
 *  + 在public文件夹下的index.html 
 *  + <meta name="referrer" content="no-referrer">
*/
</script>

<style lang='less' scoped>
//@import url(); 引入公共css类
.article-item {
  .title {
    font-size: 16px;
    color: #3a3a3a;
    // line-clamp: wrap;
  }
  /deep/ .van-cell__value {
    flex: unset;
    width: 116px;
    height: 73px;
    margin-left: 12px;
  }
  .right-cover {
    width: 116px;
    height: 73px;
  }
  .cover-wrap {
    display: flex;
    // 上下 15px  左右 0 
    padding: 15px 0;
    .cover-wrap-item {
      flex: 1;
      height: 73px;
      // &:代表父元素 排除最后一个元素的padding-right
      &:not(:last-child) {
        padding-right: 4px;
      }
      .cover-item {
        width: 100%;
        height: 73px;
      }
    }
  }
  .label-wrap {
    font-size: 11px;
    color: #b4b4b4;
    span {
      margin-right: 8px;
    }
  }
}
</style>